/**
 * 1
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-28 下午6:59
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int minOps(char ch1, char ch2) {
    int res = ch1 - ch2;
    return res < 0 ? 10 + res : res;
}

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    int res = 0;
    for (int i = 0; i < 4; ++i) {
        res += minOps(s1[i], s2[i]);
    }
    cout << res;
    return 0;
}